import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_li_ke_jie/style/common_font_style.dart';
import 'package:flutter_li_ke_jie/constant/app_constant.dart';
import 'package:flutter_li_ke_jie/ui/login/login_page.dart';
import 'package:flutter_li_ke_jie/utils/common_util.dart';
import 'package:flutter_li_ke_jie/utils/navigator_util.dart';
import 'package:flutter_li_ke_jie/utils/sputil.dart';
import '../../router/router.dart';
import '../../utils/img_util.dart';

//启动页面
class StartPage extends StatefulWidget {
  const StartPage({Key? key}) : super(key: key);

  @override
  _StartPageState createState() => _StartPageState();
}

class _StartPageState extends State<StartPage> {
  @override
  void initState() {
    //全屏
    // SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
    super.initState();
    //3秒后跳转
    _go();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        width: double.infinity,
        height: double.infinity,
        decoration: BoxDecoration(
          color: Colors.white
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Image.asset(ImageUtil.loadLocalImg("logo.png"),height: 80,width: 80,),
            const SizedBox(height: 20,),
            const Text(appName,style: titleTextStyle,)
          ],
        ),
      ),
    );
  }

  ///3秒后跳转
  void _go(){
    Future.delayed(const Duration(seconds: 3),(){
      //判断sp是否有token 有首页 没有登录
      String? token = SPUtil.getToken();
      if(CommonUtil.checkStrIsNull(token)){
        //跳转登录
        NavigatorUtil.goAndFinish(context,LOGIN_PAGE);
        // NavigatorUtil.goAndFinish(context,HOME_PAGE);
        // NavigatorUtil.goAndFinish(context,REAL_NAME_PAGE);
      }else{
        //跳转首页
        NavigatorUtil.goAndFinish(context,HOME_PAGE);
      }
    });
  }
}
